#include "tribonacci.h"
int tribonacci(int n) {
  if (n <= 1)
    return n;
  else if (n == 2)
    return 1;
  else {
    int value[3] = {0, 1, 1};
    for (int i = 0; i <= n - 3; i++) {
      int cache = value[0] + value[1] + value[2];
      value[0] = value[1];
      value[1] = value[2];
      value[2] = cache;
    }
    return value[2];
  }
}
